package main

import (
	"github.com/nfnt/resize"
	"image"
	"image/png"
	"log"
	"os"
)

func main() {
	path := "D:\\Documents\\Pictures\\jump.PNG"
	pic, err := openPic(path)
	checkErr(err)

	pic = resize.Resize(720, 0, pic, resize.Lanczos3)
	newSavePic("D:\\Documents\\Pictures\\jump_temp.png", pic)
}

func openPic(picPath string) (image.Image, error) {
	f, err := os.Open(picPath)
	if err != nil {
		return nil, err
	}
	defer f.Close()
	return png.Decode(f)

}
func newSavePic(picPath string, pic image.Image) {
	f, _ := os.Create(picPath)
	defer f.Close()
	png.Encode(f, pic)
}
func coverSavePic(picPath string, pic image.Image) {
	f, _ := os.OpenFile(picPath, os.O_WRONLY|os.O_CREATE, 0600)
	defer f.Close()
	png.Encode(f, pic)
}

func checkErr(err error) {
	if err != nil {
		log.Fatal(err)
		// os.Exit(1)
	}
}
